package com.ruoyi.report_lqn.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.syrw.annotation.FIllBasicInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.report_lqn.domain.bo.ReportLqnGxlqtxjlbBsInfoBo;
import com.ruoyi.report_lqn.domain.vo.ReportLqnGxlqtxjlbBsInfoVo;
import com.ruoyi.report_lqn.domain.ReportLqnGxlqtxjlbBsInfo;
import com.ruoyi.report_lqn.mapper.ReportLqnGxlqtxjlbBsInfoMapper;
import com.ruoyi.report_lqn.service.IReportLqnGxlqtxjlbBsInfoService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 改性沥青弹性恢复、离析试验检测记录Service业务层处理
 *
 * @author tll
 * @date 2024-09-12
 */
@RequiredArgsConstructor
@Service
public class ReportLqnGxlqtxjlbBsInfoServiceImpl implements IReportLqnGxlqtxjlbBsInfoService {

    private final ReportLqnGxlqtxjlbBsInfoMapper baseMapper;

    /**
     * 查询改性沥青弹性恢复、离析试验检测记录
     */
    @Override
    @FIllBasicInfo
    public ReportLqnGxlqtxjlbBsInfoVo queryById(Long excelId){
        return baseMapper.selectVoById(excelId);
    }

    /**
     * 查询改性沥青弹性恢复、离析试验检测记录列表
     */
    @Override
    public TableDataInfo<ReportLqnGxlqtxjlbBsInfoVo> queryPageList(ReportLqnGxlqtxjlbBsInfoBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<ReportLqnGxlqtxjlbBsInfo> lqw = buildQueryWrapper(bo);
        Page<ReportLqnGxlqtxjlbBsInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询改性沥青弹性恢复、离析试验检测记录列表
     */
    @Override
    public List<ReportLqnGxlqtxjlbBsInfoVo> queryList(ReportLqnGxlqtxjlbBsInfoBo bo) {
        LambdaQueryWrapper<ReportLqnGxlqtxjlbBsInfo> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<ReportLqnGxlqtxjlbBsInfo> buildQueryWrapper(ReportLqnGxlqtxjlbBsInfoBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportLqnGxlqtxjlbBsInfo> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getTotalPage() != null, ReportLqnGxlqtxjlbBsInfo::getTotalPage, bo.getTotalPage());
        lqw.eq(bo.getPage() != null, ReportLqnGxlqtxjlbBsInfo::getPage, bo.getPage());
        lqw.eq(StringUtils.isNotBlank(bo.getJilbh()), ReportLqnGxlqtxjlbBsInfo::getJilbh, bo.getJilbh());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancdwmc()), ReportLqnGxlqtxjlbBsInfo::getJiancdwmc, bo.getJiancdwmc());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcbwyt()), ReportLqnGxlqtxjlbBsInfo::getGongcbwyt, bo.getGongcbwyt());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpmc()), ReportLqnGxlqtxjlbBsInfo::getYangpmc, bo.getYangpmc());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpbh()), ReportLqnGxlqtxjlbBsInfo::getYangpbh, bo.getYangpbh());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpsl()), ReportLqnGxlqtxjlbBsInfo::getYangpsl, bo.getYangpsl());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpzt()), ReportLqnGxlqtxjlbBsInfo::getYangpzt, bo.getYangpzt());
        lqw.eq(bo.getYangpsj() != null, ReportLqnGxlqtxjlbBsInfo::getYangpsj, bo.getYangpsj());
        lqw.eq(StringUtils.isNotBlank(bo.getShiyjcrq()), ReportLqnGxlqtxjlbBsInfo::getShiyjcrq, bo.getShiyjcrq());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjwd()), ReportLqnGxlqtxjlbBsInfo::getShiytjwd, bo.getShiytjwd());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjsd()), ReportLqnGxlqtxjlbBsInfo::getShiytjsd, bo.getShiytjsd());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyj()), ReportLqnGxlqtxjlbBsInfo::getJiancyj, bo.getJiancyj());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyj()), ReportLqnGxlqtxjlbBsInfo::getPandyj, bo.getPandyj());
        lqw.eq(StringUtils.isNotBlank(bo.getZhuyyqsbmcjbh()), ReportLqnGxlqtxjlbBsInfo::getZhuyyqsbmcjbh, bo.getZhuyyqsbmcjbh());
        lqw.eq(StringUtils.isNotBlank(bo.getFujsm()), ReportLqnGxlqtxjlbBsInfo::getFujsm, bo.getFujsm());
        lqw.eq(StringUtils.isNotBlank(bo.getBaobmc()), ReportLqnGxlqtxjlbBsInfo::getBaobmc, bo.getBaobmc());
        lqw.eq(StringUtils.isNotBlank(bo.getBaobbh()), ReportLqnGxlqtxjlbBsInfo::getBaobbh, bo.getBaobbh());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcmc()), ReportLqnGxlqtxjlbBsInfo::getGongcmc, bo.getGongcmc());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancr()), ReportLqnGxlqtxjlbBsInfo::getJiancr, bo.getJiancr());
        lqw.eq(StringUtils.isNotBlank(bo.getJilr()), ReportLqnGxlqtxjlbBsInfo::getJilr, bo.getJilr());
        lqw.eq(StringUtils.isNotBlank(bo.getFuhr()), ReportLqnGxlqtxjlbBsInfo::getFuhr, bo.getFuhr());
        lqw.eq(bo.getRiq() != null, ReportLqnGxlqtxjlbBsInfo::getRiq, bo.getRiq());
        lqw.eq(StringUtils.isNotBlank(bo.getShebIds()), ReportLqnGxlqtxjlbBsInfo::getShebIds, bo.getShebIds());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyjIds()), ReportLqnGxlqtxjlbBsInfo::getJiancyjIds, bo.getJiancyjIds());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyjIds()), ReportLqnGxlqtxjlbBsInfo::getPandyjIds, bo.getPandyjIds());
        lqw.eq(StringUtils.isNotBlank(bo.getQuydd()), ReportLqnGxlqtxjlbBsInfo::getQuydd, bo.getQuydd());
        lqw.eq(StringUtils.isNotBlank(bo.getGaixjmc()), ReportLqnGxlqtxjlbBsInfo::getGaixjmc, bo.getGaixjmc());
        lqw.eq(StringUtils.isNotBlank(bo.getGaixlqzl()), ReportLqnGxlqtxjlbBsInfo::getGaixlqzl, bo.getGaixlqzl());
        lqw.eq(StringUtils.isNotBlank(bo.getJizlqcd()), ReportLqnGxlqtxjlbBsInfo::getJizlqcd, bo.getJizlqcd());
        lqw.eq(StringUtils.isNotBlank(bo.getJizlqzl()), ReportLqnGxlqtxjlbBsInfo::getJizlqzl, bo.getJizlqzl());
        lqw.eq(StringUtils.isNotBlank(bo.getJizlqbh()), ReportLqnGxlqtxjlbBsInfo::getJizlqbh, bo.getJizlqbh());
        lqw.eq(StringUtils.isNotBlank(bo.getHuifSybh1()), ReportLqnGxlqtxjlbBsInfo::getHuifSybh1, bo.getHuifSybh1());
        lqw.eq(bo.getHuifSycd1() != null, ReportLqnGxlqtxjlbBsInfo::getHuifSycd1, bo.getHuifSycd1());
        lqw.eq(bo.getHuifClcd1() != null, ReportLqnGxlqtxjlbBsInfo::getHuifClcd1, bo.getHuifClcd1());
        lqw.eq(bo.getHuifCz1() != null, ReportLqnGxlqtxjlbBsInfo::getHuifCz1, bo.getHuifCz1());
        lqw.eq(bo.getHuifHfl1() != null, ReportLqnGxlqtxjlbBsInfo::getHuifHfl1, bo.getHuifHfl1());
        lqw.eq(StringUtils.isNotBlank(bo.getHuifSybh2()), ReportLqnGxlqtxjlbBsInfo::getHuifSybh2, bo.getHuifSybh2());
        lqw.eq(bo.getHuifSycd2() != null, ReportLqnGxlqtxjlbBsInfo::getHuifSycd2, bo.getHuifSycd2());
        lqw.eq(bo.getHuifClcd2() != null, ReportLqnGxlqtxjlbBsInfo::getHuifClcd2, bo.getHuifClcd2());
        lqw.eq(bo.getHuifCz2() != null, ReportLqnGxlqtxjlbBsInfo::getHuifCz2, bo.getHuifCz2());
        lqw.eq(bo.getHuifHfl2() != null, ReportLqnGxlqtxjlbBsInfo::getHuifHfl2, bo.getHuifHfl2());
        lqw.eq(bo.getHuifPjz() != null, ReportLqnGxlqtxjlbBsInfo::getHuifPjz, bo.getHuifPjz());
        lqw.eq(StringUtils.isNotBlank(bo.getRuanhdSybh1()), ReportLqnGxlqtxjlbBsInfo::getRuanhdSybh1, bo.getRuanhdSybh1());
        lqw.eq(bo.getRuanhdR11() != null, ReportLqnGxlqtxjlbBsInfo::getRuanhdR11, bo.getRuanhdR11());
        lqw.eq(bo.getRuanhdR21() != null, ReportLqnGxlqtxjlbBsInfo::getRuanhdR21, bo.getRuanhdR21());
        lqw.eq(bo.getRuanhdCz1() != null, ReportLqnGxlqtxjlbBsInfo::getRuanhdCz1, bo.getRuanhdCz1());
        lqw.eq(bo.getRuanhdLx1() != null, ReportLqnGxlqtxjlbBsInfo::getRuanhdLx1, bo.getRuanhdLx1());
        lqw.eq(StringUtils.isNotBlank(bo.getRuanhdSybh2()), ReportLqnGxlqtxjlbBsInfo::getRuanhdSybh2, bo.getRuanhdSybh2());
        lqw.eq(bo.getRuanhdR12() != null, ReportLqnGxlqtxjlbBsInfo::getRuanhdR12, bo.getRuanhdR12());
        lqw.eq(bo.getRuanhdR22() != null, ReportLqnGxlqtxjlbBsInfo::getRuanhdR22, bo.getRuanhdR22());
        lqw.eq(bo.getRuanhdCz2() != null, ReportLqnGxlqtxjlbBsInfo::getRuanhdCz2, bo.getRuanhdCz2());
        lqw.eq(bo.getRuanhdLx2() != null, ReportLqnGxlqtxjlbBsInfo::getRuanhdLx2, bo.getRuanhdLx2());
        lqw.eq(StringUtils.isNotBlank(bo.getRuanhdSybh3()), ReportLqnGxlqtxjlbBsInfo::getRuanhdSybh3, bo.getRuanhdSybh3());
        lqw.eq(bo.getRuanhdR13() != null, ReportLqnGxlqtxjlbBsInfo::getRuanhdR13, bo.getRuanhdR13());
        lqw.eq(bo.getRuanhdR23() != null, ReportLqnGxlqtxjlbBsInfo::getRuanhdR23, bo.getRuanhdR23());
        lqw.eq(bo.getRuanhdCz3() != null, ReportLqnGxlqtxjlbBsInfo::getRuanhdCz3, bo.getRuanhdCz3());
        lqw.eq(bo.getRuanhdLx3() != null, ReportLqnGxlqtxjlbBsInfo::getRuanhdLx3, bo.getRuanhdLx3());
        lqw.eq(StringUtils.isNotBlank(bo.getRuanhdSybh4()), ReportLqnGxlqtxjlbBsInfo::getRuanhdSybh4, bo.getRuanhdSybh4());
        lqw.eq(bo.getRuanhdR14() != null, ReportLqnGxlqtxjlbBsInfo::getRuanhdR14, bo.getRuanhdR14());
        lqw.eq(bo.getRuanhdR24() != null, ReportLqnGxlqtxjlbBsInfo::getRuanhdR24, bo.getRuanhdR24());
        lqw.eq(bo.getRuanhdCz4() != null, ReportLqnGxlqtxjlbBsInfo::getRuanhdCz4, bo.getRuanhdCz4());
        lqw.eq(bo.getRuanhdLx4() != null, ReportLqnGxlqtxjlbBsInfo::getRuanhdLx4, bo.getRuanhdLx4());
        lqw.eq(bo.getRuanhdPjz() != null, ReportLqnGxlqtxjlbBsInfo::getRuanhdPjz, bo.getRuanhdPjz());
        lqw.eq(bo.getHuifLscd1() != null, ReportLqnGxlqtxjlbBsInfo::getHuifLscd1, bo.getHuifLscd1());
        lqw.eq(bo.getHuifLscd2() != null, ReportLqnGxlqtxjlbBsInfo::getHuifLscd2, bo.getHuifLscd2());
        lqw.eq(bo.getHuifSyhscd1() != null, ReportLqnGxlqtxjlbBsInfo::getHuifSyhscd1, bo.getHuifSyhscd1());
        lqw.eq(bo.getHuifSyhscd2() != null, ReportLqnGxlqtxjlbBsInfo::getHuifSyhscd2, bo.getHuifSyhscd2());
        return lqw;
    }

    /**
     * 新增改性沥青弹性恢复、离析试验检测记录
     */
    @Override
    public Boolean insertByBo(ReportLqnGxlqtxjlbBsInfoBo bo) {
        ReportLqnGxlqtxjlbBsInfo add = BeanUtil.toBean(bo, ReportLqnGxlqtxjlbBsInfo.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setExcelId(add.getExcelId());
        }
        return flag;
    }

    /**
     * 修改改性沥青弹性恢复、离析试验检测记录
     */
    @Override
    public Boolean updateByBo(ReportLqnGxlqtxjlbBsInfoBo bo) {
        ReportLqnGxlqtxjlbBsInfo update = BeanUtil.toBean(bo, ReportLqnGxlqtxjlbBsInfo.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(ReportLqnGxlqtxjlbBsInfo entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除改性沥青弹性恢复、离析试验检测记录
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
